package d.n.d.dao;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import org.springframework.stereotype.Repository;
import d.n.d.domain.User;

/**
 * 
 * @author D.N.D
 *
 */
@Repository
public class UserDaoImpl implements UserDao {

	@PersistenceContext
	private EntityManager em;



	public User getUser(String userName, String password) {

		TypedQuery<User> query = em
				.createQuery(
						"SELECT u FROM User u WHERE u.userName =:userName and u.password =:password",
						User.class)
				.setParameter("userName", userName)
				.setParameter("password", password);

		List<User> list = query.getResultList();
		if (list.size() == 0)
			return null;
		return list.get(0);
	}
}
